<?php

//Initial date: 2009-05-13
//Last change: 2009-05-31 by Kamil Jaskiewicz

class projects extends DBTable
{
	public $DB;

	public function __construct($ID=false)
	{
		parent::__construct("projects");
		if ($ID) {
			$this->findID($ID);
		}
	}

	public function findID($id) {
		$this->DB->query("SELECT * FROM vw_projects WHERE project_id='$id'");
		return $this->getNext();
	}
	
	public function selectAll()
	{
		$this->DB->query("SELECT * FROM vw_projects");
		return $this->DB->RowCount;
	}

	public function selectDepartmentsForProject($id)
	{
		$this->DB->query("SELECT pd.*, d.dept_name AS dept_name FROM project_departments AS pd LEFT JOIN departments AS d ON pd.dept_id=d.dept_id WHERE pd.project_id='$id' ");
		return $this->DB->RowCount;
	}

	public function getPossibleStatusValues()
	{
		$this->DB->query("SELECT * FROM dictionary WHERE dict_group='project_status'");
		return $this->DB->RowCount;
	}

	public function getPossiblePriorityValues()
	{
		$this->DB->query("SELECT * FROM dictionary WHERE dict_group='project_priority'");
		return $this->DB->RowCount;
	}

	public function getPossibleTypeValues()
	{
		$this->DB->query("SELECT * FROM dictionary WHERE dict_group='project_type'");
		return $this->DB->RowCount;
	}

	public function delete($id)
	{
		$this->DB->query("DELETE FROM projects WHERE project_id='$id'");
		return $this->DB->RowCount;
	}
	
	public function deleteDeptForProject($dept_id, $p_id)
	{
		$this->DB->query("DELETE FROM project_departments WHERE dept_id='$dept_id' AND project_id='$p_id'");
		return $this->DB->RowCount;
	}
}

?>
